#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;
using ull = unsigned long long;

int n, m;
set<ull> a;
ull b[N];
int c[1005], cnt, tot;
int ans;
ull encode(string& s) {
  ull res = 0;
  for (char c : s) {
    res = res * 26 + c - 'a';
  }
  return res;
}
void solve() {
  map<ull, ull> mp;
  rep(i, 1, n) {
    if (a.count(b[i])) {
      if (!mp.count(b[i])) mp[b[i]] = ++tot;  // new string in b
      b[i] = mp[b[i]];
    } else {
      b[i] = 0;
    }
  }
  if (tot == 0) {
    cout << 0 << endl << 0;
    return;
  }
  ans = n;
  c[0] = n * 2;  // 0 不会被当成新单词
  int l = 0, r = 0;
  while (true) {
    if (--c[b[l++]] == 0) cnt--;
    while (cnt < tot && r < n) {
      if (++c[b[++r]] == 1) cnt++;
    }
    if (cnt < tot) break;
    while (c[b[l]] > 1) {
      c[b[l++]]--;
    }
    ans = min(ans, r + 1 - l);
  }
  cout << tot << endl << ans;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> m;
  rep(i, 1, m) {
    string x;
    cin >> x;
    a.insert(encode(x));
  }
  cin >> n;
  rep(i, 1, n) {
    string x;
    cin >> x;
    b[i] = encode(x);
  }
  solve();
  return 0;
}